import {createRouter,createWebHistory } from 'vue-router' 

const router  = createRouter({
  history:createWebHistory(),
  scrollBehavior(to,from,savedPosition){
    // savedPosition 之前滚动的距离
    if (savedPosition) {
      return savedPosition
    } else {
      // behavior 丝滑顺畅
      return { top: 0,behavior:'smooth' }
    }
  },
  routes:[
    {
      path:'/playground',
      component:()=>import('@/views/playground/index.vue')
    },
    {
      path:'/login',
      component:()=>import('@/views/Login/index.vue')
    },
    {
      path:'/',
      component:()=>import('@/views/Layout/index.vue'),
      children:[
        { path:'',component:()=>import('@/views/home/index.vue')},
        { path:'category/:id',component:()=>import('@/views/category/index.vue')},
        { path:'/category/sub/:id',component:()=>import('@/views/category/sub.vue')},
        { path:'/goods/:id',component:()=>import('@/views/goods/index.vue')}
      ]
    }
  ]
})
export default router